package com.xr.org.emp;

import com.xr.common.CommUtil;
import com.xr.common.Tools;
import com.xr.system.User;
import com.bstek.dorado.data.*;
import com.bstek.dorado.data.db.SqlDataset;
import com.bstek.dorado.common.*;

/**
 * datasetListener
 */
public class datasetListener extends AbstractDatasetListener {
  public boolean beforeLoadData(Dataset dataset)
     throws Exception {
	  SqlDataset ds = (SqlDataset) dataset;
	  DoradoContext context = DoradoContext.getContext();  
	  User user=(User)context.getAttribute(context.SESSION,"User");
		String className = dataset.parameters().getString("className");
		String sql = "";
		if (className != null && className.equals("addressBook_datasetAddress")) { //
			sql += ds.getSql();
		 
			sql += CommUtil.setConditionSQL(ds); 
			ds.setSql(sql);
		}
		if (className != null && className.equals("myWorkDiary_datasetDay")) { //
			
			sql = "select * from emp_work_diary where dr=0 and onoff_station_id="
				+ ds.parameters().getString("onoff_station_id");
		if(ds.parameters().getDate("WORK_DATE")!=null){
			sql+=" and to_char(work_DATE,'yyyyMMdd')='"+Tools.format(ds.parameters().getDate("WORK_DATE"),"yyyyMMdd")+"'";
		}
		if(ds.parameters().getDate("START_TIME")!=null){
			sql+=" and work_DATE>=to_date('"
				+ Tools.format(ds.parameters().getDate("START_TIME"),
				"yyyy-MM-dd") + "','yyyy-MM-dd') ";
		}
		if(ds.parameters().getDate("END_TIME")!=null){
			sql+=" and work_DATE<=to_date('"
				+ Tools.format(ds.parameters().getDate("END_TIME"),
				"yyyy-MM-dd") + "','yyyy-MM-dd') ";
		}
		 
			//sql += CommUtil.setConditionSQL(ds); 
			ds.setSql(sql);
		}
	/*	if (className != null && className.equals("myWorkDiary_datasetDay")) { //
			sql += ds.getSql();
			 
			sql += CommUtil.setConditionSQL(ds); 
			ds.setSql(sql);
		}*/
		if (className != null && className.equals("rAndPList_datasetRandP")) { //
			sql += ds.getSql(); 
			sql += CommUtil.setConditionSQL(ds); 
			ds.setSql(sql);
		}
		if (className != null && className.equals("change_rAndPList_datasetRandP")) { //
			sql += ds.getSql(); 
			if(ds.parameters().getString("RANDP_MONTH")!=null && !ds.parameters().getString("RANDP_MONTH").equals("")){
				sql+=" and to_char(RANDP_DATE,'yyyyMM')='"+ds.parameters().getString("RANDP_MONTH")+"'";
			}
			sql += CommUtil.setConditionSQL(ds); 
			ds.setSql(sql);
		}
    return true;
  }

}
